/**============================================================================
 Confidential Information - Limited distribution to authorized persons only.
 This software is protected as an unpublished work under the U.S. Copyright
 Act of 1976.

 Copyright (c) 2012, BluePhoenix Solutions, Inc. All rights reserved.
 ----------------------------------------------------------------------------
 file......: ChangeStatusProxy.java
 Author....: Vyacheslav Kovalyov
 Created...: 1/20/12

 Description:

 ============================================================================*/
package com.bphx.android.utils;

import com.bphx.android.ui.listeners.IChangeStatusListener;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Vyacheslav Kovalyov
 * @version 1.0
 */
public class ChangeStatusProxy {

    private ChangeStatusProxy() {
        listeners = new HashMap<String, IChangeStatusListener<?>>();
    }

    public static ChangeStatusProxy getInstance() {
        if (instance == null) {
            instance = new ChangeStatusProxy();
        }

        return instance;
    }

    @SuppressWarnings("unchecked")
    public void changeStatusFor(String key, Object status, String... params) {
        IChangeStatusListener<Object> statusListener = 
                (IChangeStatusListener<Object>)listeners.get(key);
        if(statusListener != null){
            statusListener.changeStatus(status, params);
        }
    }
    
    public void putListener(String key, IChangeStatusListener<?> statusListener){
        listeners.put(key, statusListener);
    }

    public void removeListener(String key){
        listeners.remove(key);
    }

    private static ChangeStatusProxy instance;
    private Map<String, IChangeStatusListener<?>> listeners;
}
